﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Abp.Domain.Services;
using Abp.UI;
using FwProject.Core.Restaurant;

namespace FwProject.Manager
{
    public class RestaurantUserManager: IDomainService
    {
        private readonly IRepository<RestaurantUserInfo, Guid> _restaurantuserRepository;
        public RestaurantUserManager(IRepository<RestaurantUserInfo, Guid> restaurantuserRepository)
        {
            _restaurantuserRepository = restaurantuserRepository;

        }
        /// <summary>
        /// 添加一个餐厅人员
        /// </summary>
        /// <param name="restaurantUser"></param>
        /// <returns></returns>
        public async Task<Guid> CreateRestaurantUser(RestaurantUserInfo restaurantUser)
        {

            var model = _restaurantuserRepository.GetAll().Where(o => o.EmployeeRestaurantId == restaurantUser.EmployeeRestaurantId).FirstOrDefault();
            if (model != null)
                throw new UserFriendlyException("当前餐厅已绑定用户");

            return await _restaurantuserRepository.InsertAndGetIdAsync(restaurantUser);
        }
        /// <summary>
        ///修改一个餐厅人员
        /// </summary>
        /// <param name="restaurantUser"></param>
        /// <returns></returns>
        public async Task UpdateRestaurantUser(RestaurantUserInfo restaurantUser)
        {

            await _restaurantuserRepository.UpdateAsync(restaurantUser);
        }
        /// <summary>
        ///  delete 一个餐厅人员
        /// </summary>
        /// <param name="restaurantUser"></param>
        /// <returns></returns>
        public async Task DeleteRestaurantUser(RestaurantUserInfo restaurantUser)
        {

            await _restaurantuserRepository.DeleteAsync(restaurantUser);
        }

    }
}
